package [basepackage].service;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import com.codahale.metrics.annotation.Counted;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;

import lombok.extern.slf4j.Slf4j;
import [basepackage].bean.Customer;
import [basepackage].bean.models.BaseJob;
import [basepackage].dao.primary.BaseJobMapper;

@Service
@Slf4j
public class TestService {

	@Autowired
	private BaseJobMapper baseJobMapper;

	@Autowired
	private RestTemplate restTemplate;

	@Counted
	public void callCount() {
		System.out.println("aaaaaaaaaaaaaaaaaaaaaa");
	}

	public void save(Customer saveobj) {
		// TODO 保存到数据库
		log.info("name={}", saveobj.getName());
	}

	public Customer get(String id) {
		Customer retobj = new Customer("lishi", 28, new Date());
		return retobj;
	}

	public BaseJob findJobById(Long id) {
		BaseJob baseJob = baseJobMapper.selectByPrimaryKey(id);
		return baseJob;
	}

	@HystrixCommand(fallbackMethod = "demoFallback")
	public String restTemplate() {
		String postForObject = restTemplate.getForObject("http://demo-micro/timeout", String.class);
		return postForObject;
	}

	@SuppressWarnings("unused")
	private String demoFallback() {
		return "error";
	}

}
